import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/brn/brn_bottom_button_panel.dart';
import 'package:yt_devops/pages/devices/device_controll/component/rate_setting/rate_setting_controller.dart';
import 'package:yt_devops/pages/devices/device_controll/component/rate_setting/rate_setting_view.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/func_utils.dart';
import 'rate_setting_edit_controller.dart';

class RateSettingEditPage extends GetView<RateSettingEditController> {
  const RateSettingEditPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: true,
      appBar: AppBarWidget.defaultAppBar(FuncUtils.formatMessage(
          resKey: ResKey.rateSetting, defaultMessage: '费率设置')),
      body: SingleChildScrollView(
        child: RateSetting(
          tag: 'edit',
          deviceId: controller.deviceId,
          isEdit: true,
        ),
      ),
      bottomNavigationBar: DecoratedBox(
        decoration: const BoxDecoration(color: Colour.white),
        child: SafeArea(
          child: YtBrnBottomButtonPanel(
            mainButtonName: 'siteMonitor.issueParameters'.tr,
            mainButtonOnTap: () {
              if (FocusScope.of(context).hasFocus) {
                FocusScope.of(context).unfocus();
              }
              RateSettingController rateSetting = Get.find(tag: 'edit');
              rateSetting.submit().then((result) {
                Get.back();
                RateSettingController rateSettingController =
                    Get.find(tag: 'detail');
                rateSettingController.getRateSetting();
              }).catchError((err) {
                print(err);
              });
            },
            secondaryButtonOnTap: () {
              Get.back();
            },
            secondaryButtonName: ResKey.cancel.tr,
            enableSecondaryButton: true,
            secondaryButtonBorder: Border.all(color: Colour.dividerColor),
          ),
        ),
      ),
    );
  }
}
